package com.liukai.novel_type.presenter.impl;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.liukai.novel_base.base.BasePresenter;
import com.liukai.novel_base.base.IBaseCallBack;
import com.liukai.novel_commons.API;
import com.liukai.novel_commons.Result;
import com.liukai.novel_commons.entities.NovelType;
import com.liukai.novel_commons.utils.RetrofitManager;
import com.liukai.novel_type.call_back.INovelTypeCallBack;
import com.liukai.novel_type.presenter.INovelTypePresenter;

import java.util.List;

import javax.net.ssl.HttpsURLConnection;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.http.HTTP;

public class NovelTypePresenterImpl extends BasePresenter<INovelTypeCallBack> implements INovelTypePresenter {

    @Override
    public void findAllNovelType() {
//        mCallBack.result("这是消息");
        Retrofit retrofit = RetrofitManager.getNovelInstance().getRetrofit();
        API api = retrofit.create(API.class);
        Call<Result> findAllNovelTypeTask = api.findAllNovelType();
        findAllNovelTypeTask.enqueue(new Callback<Result>() {
            @Override
            public void onResponse(Call<Result> call, Response<Result> response) {
                int code = response.code();
                // 请求网络成功
                if (code == HttpsURLConnection.HTTP_OK){
                    Result result = response.body();
                    mCallBack.resultFindAllNovelType(result);
                }
            }

            @Override
            public void onFailure(Call<Result> call, Throwable t) {
                Log.e("NovelTypePresenterImpl", "onFailure: ",t);
                // 请求网络失败
                mCallBack.resultFindAllNovelType(Result.fail(404,"网络请求失败",null));
            }
        });

    }

}
